<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = mysql_real_escape_string($_SESSION['user']);
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2)
	header("Location: home.php");

$page = $_POST['page'];
$per_page = $_POST['per_page'];
$start = ($page-1) * $per_page;

$result = mysql_query("SELECT * FROM referral_order WHERE complete = 1 ORDER BY timestamp DESC LIMIT $start, $per_page") or die(mysql_error());

while($row = mysql_fetch_array($result))
{
	$user_result = mysql_query("SELECT * FROM user WHERE id = ".$row['user']);
	$user_row = mysql_fetch_array($user_result);

	echo "<tr><td>".$row['id']."</td>";
	echo "<td>".date("d M Y", $row['timestamp'])."</td>";
	echo "<td>".$user_row['paypal']."</td>";
	echo "<td>".$row['referrals']."</td>";
	echo "<td>".$row['link']."</td>";
	echo "<td>".($row['referrals'] * ($price/25))."</td>";
	echo "<td><a href='referral_order.php?id=".$row['id']."' class='btn btn-success btn-xs'>Details</a></td>";
	echo "</tr>";
}
?>